
// 接口



export interface Alarm {
    alert(): void;
}

export interface Light {
    lightOn(): void;
    lightOff(): void;
}

export class Car implements Alarm, Light {
    alert() {
        console.log('Car alert');
		return 'Car alert';
    }
    lightOn() {
        console.log('Car light on');
		return 'Car light on';
    }
    lightOff() {
        console.log('Car light off');
		return 'Car light off';
    }
}

// TS 类与接口
// https://segmentfault.com/a/1190000015068063



// ---------------------------------------------------------
// 泛型
interface Lengthwise {
    length: number;
}

export function loggingIdentity<T extends Lengthwise>(arg: T): T {
    console.log(arg.length);
    return arg;
}




interface SearchFunc {
  (source: string, subString: string): boolean;
}

export let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
    return source.search(subString) !== -1;
}




interface CreateArrayFunc {
    <T>(length: number, value: T): Array<T>;
}

export let CreateArrayFunc: CreateArrayFunc;
CreateArrayFunc = function<T>(length: number, value: T): Array<T> {
    let result: T[] = [];
    for (let i = 0; i < length; i++) {
        result[i] = value;
    }
    return result;
}





interface CreateArrayFunc22<T> {
    (length: number, value: T): Array<T>;
}

export let CreateArrayFunc22: CreateArrayFunc22<any>;
CreateArrayFunc22 = function<T>(length: number, value: T): Array<T> {
    let result: T[] = [];
    for (let i = 0; i < length; i++) {
        result[i] = value;
    }
    return result;
}

// 接口, 数据类型为对象
export interface IGlobalData {
	// name:string;——>确定属性
	// age?:number;——>可选属性
	// readonly id:number;——>只读属性
	// ——>任意属性：表示的是属性名是字符串类型，属性值是任意值类型
	[propName:string]: any;

}



